<?php
    $dom = new DomDocument;
    //if(isset($_GET['userid'])) {
    {
    //    $user_id = $_GET['userid'];
    $user_id = 1;
        mysql_connect('localhost', 'root', '12345');
        mysql_select_db('socnet');

        $query = "SELECT p.id       AS id, 
                         u.login    AS login, 
                         p.date     AS date, 
                         p.message  AS message 
                    FROM posts p JOIN users u ON
                        p.user_id = u.id 
                    WHERE p.owner_id = $user_id";
        $cursor = mysql_query($query);

        $wall = $dom->createElement('wall');
        $user = $dom->createElement('user');
        $user->appendChild($dom->createTextNode($user_id));
        $wall->appendChild($user);
        $posts = $dom->createElement('posts');
        while($row = mysql_fetch_array($cursor)) {
            $post = $dom->createElement('post');
            $id = $dom->createAttribute('id');
            $id->appendChild($dom->createTextNode($row['id']));
            $post->setAttributeNode($id);

            $user = $dom->createElement('user');
            $user->appendChild($dom->createTextNode($row['login']));
            $post->appendChild($user);

            $date = $dom->createElement('date');
            $date->appendChild($dom->createTextNode($row['date']));
            $post->appendChild($date);

            $message = $dom->createElement('message');
            $message->appendChild($dom->createTextNode($row['message']));
            $post->appendChild($message);

            $posts->appendChild($post);
        }

        $wall->appendChild($posts);

        $dom->appendChild($wall);

    }
    echo $dom->saveXML();
